﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmazonDynamoDBStub.Models;
using Amazon.DynamoDBv2.Model;

namespace AmazonDynamoDBStub.Extensions
{
    public static class DynamoDBAttributeExtensions
    {
        public static bool IsArray(this DynamoDBAttribute dynamoDBAttribute)
        {
            if (dynamoDBAttribute == null)
            {
                throw new ArgumentNullException("dynamoDBAttribute");
            }

            string[] arrayAttributeTypes = { "SS", "NS", "BS" };
            return arrayAttributeTypes.Contains(dynamoDBAttribute.AttributeType);
        }

        public static Dictionary<string, AttributeValue> ToItemDictionary(this IGrouping<Guid, DynamoDBAttribute> item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return item.ToDictionary(
                attribute => attribute.AttributeName, 
                attribute => new AttributeValue().WithValue(attribute.AttributeValue, attribute.AttributeType));
        }
    }
}
